home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
monitory
/
lav
/
uptime.c
< prev
Wrap
C/C++ Source or Header
|
1993-06-12
|
1KB
|
49 lines
#include <exec/exec.h>
#include <clib/exec_protos.h>
#include "lavd.h"
static const char PortName[] = "lavd";
struct MsgPort *lavdPort = NULL;
struct MsgPort *RepPort = NULL; /* Reply port. */
lavdMsg Req;
main()
{
if ((RepPort = CreateMsgPort()) == NULL) {
PutStr("Couldn't create a message port.\n");
goto exitmain;
}
Req.lm_Message.mn_ReplyPort = RepPort;
Req.lm_Message.mn_Length = sizeof(lavdMsg);
Req.Class = LAV_ALL;
/* Forbid so the port doesn't go away... */
Forbid();
if ((lavdPort = FindPort(PortName)) == NULL) {
Permit();
PutStr("Demon not running.\n");
goto exitmain;
}
PutMsg (lavdPort, &Req);
Permit();
WaitPort(RepPort); /* Wait for the reply. */
/* Format the result. */
Printf("Up %ld days, %ld:%02ld, load average %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
(LONG) Req.Uptime / 86400, (LONG) Req.Uptime / 3600,
(LONG) ((Req.Uptime / 60) % 60), (LONG) (Req.L1 / 100),
(LONG) ((Req.L1 - Req.L1 / 100) % 100), (LONG) (Req.L2 / 100),
(LONG) ((Req.L2 - Req.L2 / 100) % 100), (LONG) Req.L3 / 100,
(LONG) ((Req.L3 - Req.L3 /100) % 100));
exitmain:
if (RepPort != NULL) {
DeleteMsgPort(RepPort);
}
exit(0);
}